package com.tledu.stu_manager.controller.role; /**
 *
 */

import com.alibaba.fastjson.JSONObject;
import com.tledu.stu_manager.constant.Constant;
import com.tledu.stu_manager.dao.RoleDao;
import com.tledu.stu_manager.exception.CustomException;
import com.tledu.stu_manager.result.Result;
import com.tledu.stu_manager.service.RoleService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "RoleBatchDelServlet", value = "/role/batch_del")
public class RoleBatchDelServlet extends HttpServlet {
    private RoleService roleService;

    @Override
    public void init() throws ServletException {
        super.init();
        roleService = new RoleService(new RoleDao());
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(Constant.CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String idList = request.getParameter("idList");
        try {
            roleService.batchDelRole(idList);
            out.print(JSONObject.toJSONString(new Result(200, true, "删除成功")));
        } catch (CustomException e) {
            e.printStackTrace();
            out.print(JSONObject.toJSONString(new Result(500, false, e.getMessage())));
        }
    }
}
